package com.jlf.tool.validation;


import com.jlf.tool.validation.constraint.MobileConstraintValidator;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;
import jakarta.validation.constraints.Pattern;

import java.lang.annotation.Documented;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * 手机号码
 *
 * @author wujr
 * 2021/1/13
 * @version 1.0
 * 变更历史
 * [wujr 2021/1/13 1.0 新增]
 */
@Documented
@Constraint(validatedBy = {MobileConstraintValidator.class})
@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE })
@Retention(RUNTIME)
@Repeatable(Mobile.List.class)
public @interface Mobile {
    String message() default "{javax.validation.constraints.Mobile.message}";

    Class<?>[] groups() default { };

    Class<? extends Payload>[] payload() default { };

    /**
     * @return an additional regular expression the annotated element must match. The default
     * is any string ('^[1][3,4,5,6,7,8,9][0-9]{9}$')
     */
    String regexp() default "^[1][3,4,5,6,7,8,9][0-9]{9}$";

    /**
     * @return used in combination with {@link #regexp()} in order to specify a regular
     * expression option
     */
    Pattern.Flag[] flags() default { };

    /**
     * Defines several {@code @Mobile} constraints on the same element.
     *
     * @see Mobile
     */
    @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE })
    @Retention(RUNTIME)
    @Documented
    @interface List {
        Mobile[] value();
    }
}
